<?

function autologin_from_pref() {
	
	global $options,$pagenow;
	
	$login = in_array( $pagenow, array( 'wp-login.php', 'wp-register.php' ) );
	
	if ( ! is_user_logged_in() &&
	     $login == false &&
	     $_POST['autologin_fail'] != true &&
	     ! empty ( $options['autologin_user'] ) &&
	     ! empty ( $options['autologin_pass'] ) ) {
		
		$creds = array( 'user_login' => $options['autologin_user'], 'user_password' => $options['autologin_pass'], 'remember' => true);
		
		$user = wp_signon( $creds, false );
		
		if ( is_wp_error($user) ) {
	    
	    $_POST['autologin_fail'] = true;
	    
	  }
	  
	  wp_redirect( home_url(), 200 );
	  
  }
  
}

add_action( 'init', 'autologin_from_pref' );

?>